package com.tju.eduservice.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tju.Result;
import com.tju.eduservice.entity.EduCourse;
import com.tju.eduservice.entity.EduTeacher;
import com.tju.eduservice.service.EduCourseService;
import com.tju.eduservice.service.EduTeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/eduservice/indexfront")
public class IndexFrontController {
    @Autowired
    private EduCourseService courseService;

    @Autowired
    EduTeacherService teacherService;

    //查询前八条热门课程  查询前四个名师
    @Cacheable(key = "'teacherAndCourse'",value = "selectList")
    @GetMapping("index")
    public Result index(){
        //前8条热门课程
        QueryWrapper<EduCourse> wrapper1 = new QueryWrapper<>();
        wrapper1.orderByDesc("id");
        wrapper1.last("limit 8");
        List<EduCourse> courseList = courseService.list(wrapper1);

        //前4条热门讲师
        QueryWrapper<EduTeacher> wrapper2 = new QueryWrapper<>();
        wrapper2.orderByDesc("id");
        wrapper2.last("limit 4");
        List<EduTeacher> teacherList = teacherService.list(wrapper2);

        return Result.ok().data("courses",courseList).data("teachers",teacherList);


    }

}
